﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        public string StoreInfo()
        {
            string mystyle = this.Label_Inserted;
            string str_TempletLayout = this.GetParamValue("YX:TempletLayout");//布局方式
            string WhetherOmit = this.GetParamValue("YX:WhetherOmit");//是否省略
            string ContentCharacter = this.GetParamValue("YX:ContentCharacter");//内容长度
            int storeId = ChangeHope.WebPage.PageRequest.GetInt("StoreId");
            YXShop.BLL.Product.Productclass probll = new YXShop.BLL.Product.Productclass();
            YXShop.BLL.Product.ProductInfo pibll = new YXShop.BLL.Product.ProductInfo();
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            if (storeId < 0)
            {
                mystyle = "该店铺不存在.";
            }
            if (!string.IsNullOrEmpty(mystyle))
            {
                YXShop.BLL.Shop.Shop bll = new YXShop.BLL.Shop.Shop();
                YXShop.Model.Shop.Shop model = bll.GetModelById(storeId);
                if (model != null)
                {
                    //店铺名称
                    if (mystyle.IndexOf("[#StoreName]") > -1)
                    {
                        mystyle = mystyle.Replace("[#StoreName]", model.Shopname);
                    }
                    //店铺主营行业
                    if (mystyle.IndexOf("[#BusinessProduct]") > -1)
                    {
                        string BusinessProductId = model.Categories.ToString();
                        YXShop.Model.Product.Productclass promodel = probll.GetModelID(Convert.ToInt32(BusinessProductId));
                        string BusinessProductName = string.Empty;
                        if (promodel != null)
                        {
                            BusinessProductName = promodel.Name;
                        }
                        mystyle = mystyle.Replace("[#BusinessProduct]", BusinessProductName);
                    }
                    //店铺Logo
                    if (mystyle.IndexOf("[#StoreLogo]") > -1)
                    {
                        string shopsign = model.Shopsign;
                        if (shopsign != "")
                        {
                            mystyle = mystyle.Replace("[#StoreLogo]", sp.DummyPaht + shopsign);
                        }
                        else
                        {
                            mystyle = mystyle.Replace("[#StoreLogo]", sp.DummyPaht + "images/NaughtImages.gif");
                        }
                    }

                    //店铺介绍
                    if (mystyle.IndexOf("[#StoreContent]") > -1)
                    {
                        string shopIntroduction = model.Content;
                        int ContentCount = 4;
                        if (!string.IsNullOrEmpty(ContentCharacter))
                        {
                            if (ChangeHope.Common.ValidateHelper.IsNumber(ContentCharacter))
                            {
                                ContentCount = Convert.ToInt32(ContentCharacter);
                            }
                        }
                        if (WhetherOmit == "True")
                        {
                            shopIntroduction = ChangeHope.Common.StringHelper.SubStringAndAppend(shopIntroduction, ContentCount, "...");
                        }
                        else
                        {
                            shopIntroduction = ChangeHope.Common.StringHelper.SubStringAndAppend(shopIntroduction, ContentCount, "");
                        }

                        if (shopIntroduction != "")
                        {
                            mystyle = mystyle.Replace("[#StoreContent]", shopIntroduction);
                        }
                        else
                        {
                            mystyle = mystyle.Replace("[#StoreContent]", shopIntroduction);
                        }
                    }
                    //店铺公告
                    if (mystyle.IndexOf("[#StoreAffiche]") > -1)
                    {
                        string shopIntroduction = model.Affiche;
                        int ContentCount = 4;
                        if (!string.IsNullOrEmpty(ContentCharacter))
                        {
                            if (ChangeHope.Common.ValidateHelper.IsNumber(ContentCharacter))
                            {
                                ContentCount = Convert.ToInt32(ContentCharacter);
                            }
                        }
                        if (WhetherOmit == "True")
                        {
                            shopIntroduction = ChangeHope.Common.StringHelper.SubStringAndAppend(shopIntroduction, ContentCount, "...");
                        }
                        else
                        {
                            shopIntroduction = ChangeHope.Common.StringHelper.SubStringAndAppend(shopIntroduction, ContentCount, "");
                        }

                        if (shopIntroduction != "")
                        {
                            mystyle = mystyle.Replace("[#StoreAffiche]", shopIntroduction);
                        }
                        else
                        {
                            mystyle = mystyle.Replace("[#StoreAffiche]", shopIntroduction);
                        }
                    }
                    //开店铺时间
                    if (mystyle.IndexOf("[#CreateStoreTime]") > -1)
                    {
                        string CreateStoreTime = Convert.ToDateTime(model.Addtime.ToString()).ToString("yyyy-MM-dd"); ;
                        if (CreateStoreTime != "")
                        {
                            mystyle = mystyle.Replace("[#CreateStoreTime]", CreateStoreTime);
                        }
                        else
                        {
                            mystyle = mystyle.Replace("[#CreateStoreTime]", CreateStoreTime);
                        }
                    }
                    //店铺等级
                    if (mystyle.IndexOf("[#StoreLevel]") > -1)
                    {
                        YXShop.BLL.Shop.ShopLevel slbll = new YXShop.BLL.Shop.ShopLevel();
                        string shoprank = model.Shoprank.ToString();
                        if (shoprank != "")
                        {
                            YXShop.Model.Shop.ShopLevel slmodel = slbll.GetModelByID(Convert.ToInt32(shoprank));
                            string rankName = string.Empty;
                            if (slmodel != null)
                            {
                                rankName = slmodel.Name;
                            }
                            mystyle = mystyle.Replace("[#StoreLevel]", rankName);
                        }
                        else
                        {
                            mystyle = mystyle.Replace("[#StoreLevel]", "");
                        }
                    }

                    //店铺主人
                    if (mystyle.IndexOf("[#StoreHost]") > -1)
                    {
                        YXShop.BLL.Member.MemberAccount mabll = new YXShop.BLL.Member.MemberAccount();
                        string uid = model.Uid.ToString();
                        if (uid != "")
                        {
                            YXShop.Model.Member.MemberAccount mamodel = mabll.GetModel(Convert.ToInt32(uid));
                            string userName = string.Empty;
                            if (mamodel != null)
                            {
                                userName = mamodel.UserId;
                            }
                            mystyle = mystyle.Replace("[#StoreHost]", userName);
                        }
                        else
                        {
                            mystyle = mystyle.Replace("[#StoreHost]", "");
                        }
                    }

                    //店铺商品数
                    if (mystyle.IndexOf("[#StoreProductCount]") > -1)
                    {

                        string uid = model.Uid.ToString();
                        if (uid != "")
                        {
                            System.Data.DataTable dt = pibll.DTGetListWhere(" and pro_PutoutID=" + uid + " and pro_PutoutType=1");
                            int proCount = 0;
                            if (dt.Rows.Count > 0)
                            {
                                proCount = dt.Rows.Count;
                            }
                            mystyle = mystyle.Replace("[#StoreProductCount]", proCount.ToString());
                        }
                        else
                        {
                            mystyle = mystyle.Replace("[#StoreProductCount]", "");
                        }
                    }

                    //店铺所在所在地区
                    if (mystyle.IndexOf("[#StoreArea]") > -1)
                    {
                        YXShop.BLL.Member.MemberInfo mibll = new YXShop.BLL.Member.MemberInfo();
                        string uid =model.Uid.ToString();
                        YXShop.Model.Member.MemberInfo mimodel = mibll.GetModel(Convert.ToInt32(uid));
                        if (mimodel != null)
                        {
                            mystyle = mystyle.Replace("[#StoreArea]", mimodel.Address);
                        }
                    }
                }
            }
            return mystyle;
        }
    }
}
